package com.banzhi.shop.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Created by HT on 2017/5/10.
 */

public class DateUtil {


    //时间戳转日期格式
    public static String getTimeData(String data) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        long l = Long.parseLong(data);
        String time = format.format(l * 1000L);
        return time;
    }

    //时间戳转日期格式
    public static String getTimeZhiData(String data) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        long l = Long.parseLong(data);
        String time = format.format(l * 1000L);
        return time;
    }

    public static String getYearData(String data) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        long l = Long.parseLong(data);
        String time = format.format(l * 1000L);
        return time;
    }

    //秒时间戳转日期
    public static String getData(String data) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long l = Long.parseLong(data);
        String time = format.format(l * 1000L);
        return time;
    }

    //毫秒时间戳转日期
    public static String getDataa(String data) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long l = Long.parseLong(data);
        String time = format.format(l * 1000L);
        return time;
    }

    //日期格式转时间戳
    public static long getTimeUnix(String date) throws ParseException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        long time = format.parse(date).getTime();
        return time;
    }

    public static long getTimeUnixs(String date) throws ParseException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = format.parse(date).getTime();
        return time;
    }

    //特卖商品倒计时
    public static String getDaoJiShiTimeUnixs(Long time) {
        String str = null;
        long h = time / 3600;
        long m = (time - h * 3600) / 60;
        long s = (time - h * 3600) % 60;
        str = NumberUtils.oneTtwo(h + "") + ":" + NumberUtils.oneTtwo(m + "") + ":" + NumberUtils.oneTtwo(s + "");
        return str;
    }
    /**
     *
     * @param 要转换的毫秒数
     * @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
     * @author fy.zhang
     */
    public static String formatDuring(long time) {
        String str = null;
        long days = time / ( 60 * 60 * 24);
        long hours = (time % ( 60 * 60 * 24)) / ( 60 * 60);
        long minutes = (time % 86400 % 3600) / 60;
        long seconds = (time % 86400 %3600) %  60 %60;
        str = NumberUtils.oneTtwo(days + "")+":"+ NumberUtils.oneTtwo(hours + "") + ":" + NumberUtils.oneTtwo(minutes + "") + ":" + NumberUtils.oneTtwo(seconds + "");
        return str;

                /*days + " days " + hours + " hours " + minutes + " minutes "
                + seconds + " seconds ";*/
    }

    /**
     * 秒转化为天小时分秒字符串
     *
     * @param seconds
     * @return String
     */
    public static String formatSeconds(long seconds) {
        String timeStr = seconds + "秒";
        if (seconds > 60) {
            long second = seconds % 60;
            long min = seconds / 60;
            timeStr = min + "分" + second + "秒";
            if (min > 60) {
                min = (seconds / 60) % 60;
                long hour = (seconds / 60) / 60;
                timeStr = hour + "小时" + min + "分" + second + "秒";
                if (hour > 24) {
                    hour = ((seconds / 60) / 60) % 24;
                    long day = (((seconds / 60) / 60) / 24);
                    timeStr = day + "天" + hour + "小时" + min + "分" + second + "秒";
                }
            }
        }
        return timeStr;
    }
    public static String miao2day(String str) {
        Double dou = Double.valueOf(str);
        int s = (int) (dou / 3600 / 24);
        return s + "";

    }

}
